package com.hackordie.operations.queries;

import com.hackordie.commons.HackOrDieResult;
import com.hackordie.commons.authorities.Profile;
import com.hackordie.exceptions.HackOrDieException;
import com.hackordie.operations.AHackOrDieOperationProfile;

public class QueryProfile extends AHackOrDieOperationProfile {

	private final int idProfile;
	private final boolean allProfiles;

	public QueryProfile() {
		super();
		this.idProfile = -1;
		this.allProfiles = true;
	}

	public QueryProfile(int idProfile) {
		super();
		this.idProfile = idProfile;
		this.allProfiles = false;
	}

	@Override
	protected boolean checkParameters() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	protected HackOrDieResult executeOperation() throws HackOrDieException {
		if (allProfiles) {
			final Profile[] profiles = profileDao.getAll();
			result.setObject(profiles);
		} else {
			final Profile profile = profileDao.get(idProfile);
			result.setObject(profile);
		}
		return result;
	}

}
